package Controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import Modelo.Vacuna;
import Modelo.ListadoVacuna;
import Vista.VentanaVacuna;

public class ControladorVentanaVacuna implements ActionListener {

	private ListadoVacuna lv;
	private VentanaVacuna ventanavacuna;
	private Vacuna vacuna;
	
public ControladorVentanaVacuna (ListadoVacuna lv, VentanaVacuna ventanavacuna, Vacuna vacuna){
	super();
	this.lv = lv;
	this.ventanavacuna = ventanavacuna;
	this.vacuna = vacuna;
	}

public ControladorVentanaVacuna(){
	super();
	this.ventanavacuna= new VentanaVacuna();
	this.ventanavacuna.setVisible(true);
	this.ventanavacuna.agregarListener(this);
	this.lv= lv;
	this.lv= new ListadoVacuna();
	
	}

private void guardar(){
	if (ventanavacuna.getCantDos().equals("")|| ventanavacuna.getCodigo().equals("")|| ventanavacuna.getDesVac().equals("")|| ventanavacuna.getNomVac().equals("")|| ventanavacuna.getTAAplicDos().equals("")|| ventanavacuna.getTEDos().equals("")){
		ventanavacuna.mostrarMensaje("No puede haber campos en blanco");
		}
	else {
		vacuna=new Vacuna(ventanavacuna.getCodigo(),ventanavacuna.getNomVac(),ventanavacuna.getDesVac(),Integer.parseInt(ventanavacuna.getCantDos()), Integer.parseInt(ventanavacuna.getTAAplicDos()), Integer.parseInt(ventanavacuna.getTEDos()), ventanavacuna.getValorCombo());
		lv.agregarVacuna(vacuna);
		ventanavacuna.mostrarMensaje("Se ha registrado la vacuna");
		ventanavacuna.LimpiarCamposVacuna();
		}
	}

private void eliminar(){
	int pos= lv.buscarVacuna(ventanavacuna.getCodigo());
	lv.eliminarVacuna(pos);
	ventanavacuna.mostrarMensaje("Vacuna Eliminada");}

private void salir() {
	ventanavacuna.dispose();
	ventanavacuna.toBack();}

@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
		 if(e.getActionCommand().equalsIgnoreCase("Guardar")){
			guardar();
		}else if(e.getActionCommand().equalsIgnoreCase("Eliminar")){
			eliminar();
		}else if(e.getActionCommand().equalsIgnoreCase("Cancelar")){
			ventanavacuna.LimpiarCamposVacuna();
		}else if(e.getActionCommand().equalsIgnoreCase("Salir")){
			salir();}
	}
	
}

